<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class promo extends CI_Controller {
	
	public function __construct() {
		parent::__construct();
		ini_set('session.cookie_httponly',1); 
		ini_set('session.use_only_cookies',1);
		$this->load->model('promo_class');
	}	 
	
	public function save_promo(){
		$post = $this->input->post();
		if(isset($post['intID'])){
			$message = '';
			$ads = $this->promo_class->get_promo($post);
			if($ads!=0){
				$message = $this->promo_class->update($post);
			} else {
				$message = $this->promo_class->insert($post);
			}
		} else {
			$message = '';
			$message = $this->promo_class->insert($post);
		}
		echo json_encode($message);
	}
	public function get_promo_list(){
		$data=array();
		
		$post = $this->input->post();	
		$promo_list = $this->promo_class->promo_list($post);
		
		if($promo_list!=0){
			foreach($promo_list as $key=>$value){
				$data['intID'][$key]=$value['intID'];
				$data['strTitle'][$key]=$value['strTitle'];
				$data['strDescription'][$key]=$value['strDescription'];
				$data['dateStart'][$key]=$value['dateStart'];
				$data['dateEnd'][$key]=$value['dateEnd'];
				$data['intStatus'][$key]=$value['intStatus'];
				$data['strPromoCode'][$key]=$value['strPromoCode'];
				$data['intPoints'][$key]=$value['intPoints'];
			}
		}
		echo json_encode($data);
	}
	public function get_promo(){
		$post = $this->input->post();
		$promo = $this->promo_class->get_promo($post);
		echo json_encode($promo);
	}
	public function delete_promo(){
		$post = $this->input->post();
		$promo = $this->promo_class->delete($post);
		echo json_encode($promo);
	}
	public function generate_qr_code(){
		$qr_code = generate_code();
		echo json_encode($qr_code);
	}
	public function get_promo_mobile(){
		$data = array();
		
		$post = $this->input->post();
		$promo_mobile = $this->get_promo_mobile_class($post);
		
		if($promo_mobile!=0){
			foreach($promo_mobile as $key=>$value){
				$data['intID'][$key]=$value['intID'];
				$data['strPromoCode'][$key]=$value['strPromoCode'];
				$data['dateEnd'][$key]=$value['dateEnd'];
				$data['intStatus'][$key]=$value['intStatus'];
			}
		}
	}
	public function save_promo_mobile(){
/* 		$post = $this->input->post();
		if(isset($post['intID'])){
			$message = '';
			$ads = $this->promo_class->get_promo($post);
			if($ads!=0){
				$message = $this->promo_class->update($post);
			} else {
				$message = $this->promo_class->insert($post);
			}
		} else {
			$message = '';
			$message = $this->promo_class->insert($post);
		}
		echo json_encode($message); */
	}
	/*public function generated_qr_code(){
		$post = $this->input->post();
		$data = $post['qrCode'];
		$qr_code = generated_qrcode($data);
		echo json_encode($qr_code);
	}*/
}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */